/****************************************************************************/
/*  File:       GraphicUserInteraction.java                                 */
/*  Author:     F. Georges - fgeorges.org                                   */
/*  Date:       2009-06-18                                                  */
/*  Tags:                                                                   */
/*      Copyright (c) 2009 Florent Georges (see end of file.)               */
/* ------------------------------------------------------------------------ */


package org.expath.pkg.exist;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * Implementation of {@link UserInteractionStrategy} for GUI.
 *
 * @author Florent Georges
 * @date   2009-06-18
 */
public class GraphicUserInteraction
        implements UserInteractionStrategy
{
    public GraphicUserInteraction(JFrame frame)
    {
        myFrame = frame;
    }

    public void messageInfo(String msg)
    {
        int type = JOptionPane.INFORMATION_MESSAGE;
        JOptionPane.showMessageDialog(myFrame, msg, "Message", type);
    }

    public void messageError(String msg)
    {
        int type = JOptionPane.ERROR_MESSAGE;
        JOptionPane.showMessageDialog(myFrame, msg, "Message", type);
    }

    public void logInfo(String msg)
    {
        // TODO: Write to a buffer, to be displayed... (as in SoapUI.)
        System.err.println(msg);
    }

    public boolean ask(String prompt, boolean dflt)
            throws PackageException
    {
        int type = JOptionPane.YES_NO_OPTION;
        int res = JOptionPane.showConfirmDialog(myFrame, prompt, "Question", type);
        return res == 0;
    }

    public String ask(String prompt, String dflt)
            throws PackageException
    {
        int type = JOptionPane.QUESTION_MESSAGE;
        // TODO: Set the initial value (aka dflt.)
        String res = (String) JOptionPane.showInputDialog(myFrame, prompt, "Question", type, null, null, dflt);
        return res;
    }

    private JFrame myFrame;
}


/* ------------------------------------------------------------------------ */
/*  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS COMMENT.               */
/*                                                                          */
/*  The contents of this file are subject to the Mozilla Public License     */
/*  Version 1.0 (the "License"); you may not use this file except in        */
/*  compliance with the License. You may obtain a copy of the License at    */
/*  http://www.mozilla.org/MPL/.                                            */
/*                                                                          */
/*  Software distributed under the License is distributed on an "AS IS"     */
/*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See    */
/*  the License for the specific language governing rights and limitations  */
/*  under the License.                                                      */
/*                                                                          */
/*  The Original Code is: all this file.                                    */
/*                                                                          */
/*  The Initial Developer of the Original Code is Florent Georges.          */
/*                                                                          */
/*  Contributor(s): none.                                                   */
/* ------------------------------------------------------------------------ */
